package wisents.wicket.form.submitingstrategy;

import pl.rabbitsoftware.EnhancedFormTester;
import wisents.wicket.form.formelements.WicketCheckboxFormElement;
import wisents.wicket.form.formelements.WicketDropDownChoiceFormElement;
import wisents.wicket.form.formelements.WicketFormElement;
import wisents.wicket.form.formelements.WicketPasswordTextFieldFormElement;
import wisents.wicket.form.formelements.WicketRadioChoiceFormElement;
import wisents.wicket.form.formelements.WicketTextAreaFormElement;
import wisents.wicket.form.formelements.WicketTextFieldFormElement;

/**
 * Created by IntelliJ IDEA. User: rabbit Date: Jan 19, 2010 Time: 9:43:23 PM To
 * change this template use File | Settings | File Templates.
 */
final class WicketFormElementConverter {
    public EnhancedFormTester convert(WicketFormElement formElement,
	    EnhancedFormTester enhancedFormTester) {

	if (formElement instanceof WicketTextAreaFormElement) {
	    return enhancedFormTester.setTextAreaValue(formElement
		    .getRelativePath(), formElement.getValue());
	} else if (formElement instanceof WicketTextFieldFormElement) {
	    return enhancedFormTester.setTextFieldValue(formElement
		    .getRelativePath(), formElement.getValue());
	} else if (formElement instanceof WicketPasswordTextFieldFormElement) {
	    return enhancedFormTester.setPasswordTextFieldValue(formElement
		    .getRelativePath(), formElement.getValue());
	} else if (formElement instanceof WicketCheckboxFormElement) {
	    return enhancedFormTester.selectCheckbox(formElement
		    .getRelativePath(), formElement.getChoiceIndex());
	} else if (formElement instanceof WicketDropDownChoiceFormElement) {
	    return enhancedFormTester.selectDropDownChoice(formElement
		    .getRelativePath(), formElement.getChoiceIndex());
	} else if (formElement instanceof WicketRadioChoiceFormElement) {
	    return enhancedFormTester.selectRadioChoice(formElement
		    .getRelativePath(), formElement.getChoiceIndex());
	} else {
	    return enhancedFormTester;
	}
    }
}
